package com.epsi.mightymaps.act;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.epsi.mightymaps.R;
import com.epsi.mightymaps.mdl.Parcours;
import com.epsi.mightymaps.mdl.PointDePassage;
import com.epsi.mightymaps.overlay.PtPassageOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class Map extends MapActivity {
	List<Overlay> mapOverlays;
	MapView mapView;

	@Override
	public void onCreate(final Bundle pSavedInstanceState) {
		super.onCreate(pSavedInstanceState);
		setContentView(R.layout.mapview);
		mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		mapOverlays = mapView.getOverlays();
	}

	@Override
	public void onResume() {
		super.onResume();
		mapOverlays.clear();
		Drawable drawable = this.getResources().getDrawable(
				R.drawable.android_robot);

		Bundle bdle = this.getParent().getIntent().getExtras();
		Parcours parc = (Parcours) bdle.get(OngletsManager.PARCOURS);

		PtPassageOverlay itemizedoverlay = new PtPassageOverlay(drawable, this);
		for (PointDePassage pdp : parc.getPoints()) {

			GeoPoint point = new GeoPoint((int) (pdp.getLat() * 1E6),
					(int) (pdp.getLng() * 1E6));
			OverlayItem overlayitem = new OverlayItem(point, pdp.getTitre(),
					pdp.getAdresse());
			itemizedoverlay.addOverlay(overlayitem);
			mapView.getController().animateTo(point);
		}

		mapOverlays.add(itemizedoverlay);
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

}